<?php
/**
 * Created by PhpStorm.
 * User: 27598
 * Date: 2019/6/20
 * Time: 14:25
 */

namespace App\Helpers;
use Modules\Admin\Entities\ScoreConfig;
use Modules\Common\Entities\User;
use Modules\Manage\Entities\ScoreLog;
use Modules\Manage\Entities\SignInLog;
use Psy\Util\Str;
use Symfony\Component\HttpFoundation\Response as FoundationResponse;
trait BaseData
{
    public function SenvenDay($price){
        $data = [];
        for($i=0;$i<7;$i++){
            array_push($data,$this->baseData($i,$price));
        }
        return $data;
    }
    public function baseData(Int $num,$price ){
        return [
            'day'=>$this->getDay($num),
            'week'=>'周'.$this->getWeek($num),
            'price'=>$price
        ];
    }
    public function getDay(Int $num){
        return now()->addDay($num)->format('Ymd');
    }
    public function getWeek(Int $num){
        return $this->formatToWeek(now()->addDay($num)->weekday());
    }
    public function formatToWeek(Int $num)
    {

       if($num == 1){
           return '一';
       }
       if($num == 2){
           return '二';
       }
       if($num == 3){
           return '三';
       }
       if($num == 4){
           return '四';
       }
       if($num == 5){
           return '五';
       }
       if($num == 6){
           return '六';
       }
       if($num == 0){
           return '日';
       }
   }
   //获取当前用户
    public function getUser($phone){
        return User::query()->where('mobile',$phone)->first();
    }
    public function getUserById($uid){
        return User::query()->find($uid);
    }
    //获取积分配置
    public function getScoreConfig($alise){

        return ScoreConfig::query()->where('alias',$alise)->first();
    }
    public function getShareNumber($mobile){
       return  ScoreLog::query()->where('mark','borker_share')->where('u_phone',$mobile)->whereBetween('created_at',[now()->startOfDay(),now()->endOfDay()])->count();
    }
    //获取积分记录
    public function getSignLog($mobile){
        return SignInLog::query()->where('mobile',$mobile)
            ->whereBetween('created_at',[now()->startOfDay(),now()->endOfDay()])
            ->first();
    }
}
